package com.clqteam.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.clqteam.dao.TempOrderDao;
import com.clqteam.util.JDBCutil;

public class TempOrderDaoImpl implements TempOrderDao{

	@Override
	public int CreatTempOrder(String tbName) {
		int flag = -1;
		StringBuffer sql = new StringBuffer();
		sql.append("CREATE TABLE ");
		sql.append(tbName);
		sql.append(" (ptId INT,ptAmount INT)");
		Connection con = JDBCutil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			flag = pst.executeUpdate();			
			JDBCutil.closeJDBC(pst, con);			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return flag;
	}

	@Override
	public int DropTempOrder(String tbName) {
		int flag = -1;
		StringBuffer sql = new StringBuffer();
		sql.append("DROP TABLE IF EXISTS ");
		sql.append(tbName);
		Connection con = JDBCutil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			flag = pst.executeUpdate();			
			JDBCutil.closeJDBC(pst, con);			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return flag;
	}
}
